<template>
  <div>
    <h1>最简单的form</h1>
    <a-form 
      :form="form"
      :hide-required-mark="true"
      label-align="right"
      :label-col="{ span: 5 }" 
      :wrapper-col="{ span: 12 }" 
      @submit="handleSubmit">
      <a-form-item label="Note">
        <a-input
          v-decorator="['note', { rules: [{ required: true, message: '请填写note!' }] }]"
        />
      </a-form-item>
      <a-form-item label="Gender">
        <a-select
          v-decorator="[
            'gender',
            { rules: [{ required: true, message: '请选择gender!' }] },
          ]"
          placeholder="请选择"
          @change="handleSelectChange"
        >
          <a-select-option value="male">male</a-select-option>
          <a-select-option value="female">female</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
        <a-button type="primary" html-type="submit">Submit</a-button>
      </a-form-item>
    </a-form>
  </div>
  
</template>

<script>
export default {
  data() {
    return {
      form: this.$form.createForm(this, { name: 'coordinated' })
    }
  },
  methods: {
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('form数据: ', values)
        }
      })
    },
    handleSelectChange(value) {
      console.log(value)
      this.form.setFieldsValue({
        note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`
      })
    }
  }
}
</script>